package com.wingsoft.homeFlow.bo;

import com.wingsoft.common.exception.ServiceException;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Date;

@Data
public class HomeFlowTaskStepBo {

    @ApiModelProperty("ID")
    private String id;

    @ApiModelProperty("任务编码")
    private String taskCode;

    @ApiModelProperty("步骤名称")
    private String stepName;

    @ApiModelProperty("交互类型：1-数据库；2-我们调第三方接口；3-第三方调我们接口")
    private Integer interactionType;

    @Getter
    @AllArgsConstructor
    public enum InteractionTypeEnum {
        DATABASE(1, "数据库"),
        WE_CALL_THIRD_API(2, "我们调第三方接口"),
        THIRD_CALL_US_API(3, "第三方调我们接口"),
        ;
        private final Integer code;
        private final String desc;

        public static InteractionTypeEnum getEnumByCode(Integer code) {
            for (InteractionTypeEnum value : InteractionTypeEnum.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            throw new ServiceException("交互类型枚举值不存在: " + code);
        }
    }

    @ApiModelProperty("步骤KEY")
    private String stepCode;

    @ApiModelProperty("数据源ID")
    private String sourceId;

    @ApiModelProperty("结果数据类型：1-单个；2-对象；3-集合")
    private Integer respDataType;

    @Getter
    @AllArgsConstructor
    public enum RespDataTypeEnum {
        SINGLE(1, "单个"),
        OBJECT(2, "对象"),
        COLLECTION(3, "集合"),
        JSON(4, "JSON"),
        ;
        private final Integer code;
        private final String desc;

        public static RespDataTypeEnum getEnumByCode(Integer code) {
            for (RespDataTypeEnum value : RespDataTypeEnum.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            throw new ServiceException("结果数据类型枚举值不存在: " + code);
        }
    }

    @ApiModelProperty("步骤类型：1-SQL；2-存储过程；3-Api接口；4-JavaBean")
    private Integer stepType;

    @Getter
    @AllArgsConstructor
    public enum StepTypeEnum {
        SQL(1, "SQL"),
        PROCEDURE(2, "存储过程"),
        API(3, "接口"),
        BEAN(4, "JavaBean"),
        ;

        private final Integer code;
        private final String desc;

        public static StepTypeEnum getEnumByCode(Integer code) {
            for (StepTypeEnum value : StepTypeEnum.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            throw new ServiceException("步骤类型枚举值不存在: " + code);
        }
    }

    @ApiModelProperty("接口类型：1-GET请求；2-POST请求；3-WebService请求")
    private Integer reqMethod;

    @Getter
    @AllArgsConstructor
    public enum ReqMethodEnum {
        GET(1, "GET"),
        POST(2, "POST"),
        WEB_SERVICE(3, "WebService"),
        ;

        private final Integer code;
        private final String desc;

        public static ReqMethodEnum getEnumByCode(Integer code) {
            for (ReqMethodEnum value : ReqMethodEnum.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            throw new ServiceException("接口类型枚举值不存在: " + code);
        }
    }

    @ApiModelProperty("请求表单")
    private String reqForm;

    @ApiModelProperty("请求体")
    private String reqBody;

    @ApiModelProperty("请求头")
    private String reqHeader;

    @ApiModelProperty("请求编码类型：1-application/x-www-form-urlencoded；2-application/json；3-text/plain")
    private String reqContentType;

    @Getter
    @AllArgsConstructor
    public enum ReqContentTypeEnum {
        FORM_URLENCODED("1", "application/x-www-form-urlencoded"),
        JSON("2", "application/json"),
        TEXT_PLAIN("3", "text/plain");
        private final String code;
        private final String desc;

        public static ReqContentTypeEnum getEnumByCode(String code) {
            for (ReqContentTypeEnum value : ReqContentTypeEnum.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            return null;
        }
    }

    @ApiModelProperty("请求模板")
    private String reqTemplate;

    @ApiModelProperty("响应模板")
    private String respTemplate;

    @ApiModelProperty("步骤顺序")
    private Integer stepIndex;

    @ApiModelProperty("是否启用 1-是 0-否")
    private Integer isUsed;

    @ApiModelProperty("创建用户ID")
    private Long createUserId;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("修改用户ID")
    private Long updateUserId;

    @ApiModelProperty("修改时间")
    private Date updateTime;

}